<?php
    $hide=$_REQUEST["hide"];
    $conn=mysqli_connect("127.0.0.1","root","","h52202");
    mysqli_query($conn,"SET NAMES utf8");
    if($hide=="getbooks"){
        $sql="SELECT * FROM books";
        $result=mysqli_query($conn,$sql);
        $arr=[];
        while(($row=mysqli_fetch_assoc($result))!=null){
            array_push($arr,$row);
        }
        echo $GET_["zy"]."(".JSON_encode($arr).")";
    }else if($hide=="getins"){
        $name=$_POST["name"];
        $auther=$_POST["auther"];
        $price=$_POST["price"];
        $count=$_POST["count"];
        $jj=$_POST["jj"];
        $content=$_POST["content"];
        $vip=$_POST["vip"];
        $sql="INSERT INTO books VALUES(0,'$name','$auther','$price','$count','$jj','$content','$vip')";
        $result=mysqli_query($conn,$sql);
        if($result){
            echo "<script>sessionStorage.state='新增成功';location='../html/status.html';</script>";
        }else{
            echo "<script>sessionStorage.state='新增失败';location='../html/status.html';</script>";
        }
    }else if($hide=="getcontent"){
        $id=$_GET["id"];
        $sql="SELECT bookname,content FROM books WHERE id=$id";
        $result=mysqli_query($conn,$sql);
        $row=mysqli_fetch_assoc($result);
        echo JSON_encode($row);
    }else if($hide=="delbooks"){
        $id=$_GET["id"];
        $sql="DELETE FROM books WHERE id=$id";
        $result=mysqli_query($conn,$sql);
        if($result){
            echo 1;
        }else{
            echo 0;
        }
    }else if($hide=="modify"){
        $id=$_GET["id"];
        $sql="SELECT * FROM books WHERE id=$id";
        $result=mysqli_query($conn,$sql);
        $row=mysqli_fetch_row($result);
        echo $_GET["zy"]."(".JSON_encode($row).")";
    }else if($hide=="modifybooks"){
        $name=$_POST["name"];
        $auther=$_POST["auther"];
        $price=$_POST["price"];
        $count=$_POST["count"];
        $jj=$_POST["jj"];
        $content=$_POST["content"];
        $vip=$_POST["vip"];
        $id=$_POST["id"];
        $sql="UPDATE books SET bookname='$name',auther='$auther',price='$price',count='$count',jj='$jj',content='$content',vip='$vip' WHERE id=$id";
        $result=mysqli_query($conn,$sql);
        if($result){
			echo "<script>sessionStorage.state='修改成功';location='../html/status.html';</script>";
		}else{
			echo "<script>sessionStorage.state='修改失败';location='../html/status.html';</script>";
		}
    }

    mysqli_close($conn);
